#!/usr/bin/env python
# -*- encoding: UTF-8 -*-
from __future__ import print_function

from flask import render_template, \
    request, redirect, url_for

from . import global_dict
from . import main
from . import Nao
from . import db

#================= 主页 ===============
@main.route('/', methods=['GET', 'POST'])
def index():
    #flash(session)
    page_title = u"主页"
    urls = [
        #{"url": url_for('.virtual_nao',name="v_red",port=9559), "text": u"添加虚拟Nao: v_red"}
    ]
    btns = [
        {
            "id": "v_red",
            "name": u"添加虚拟Nao: v_red",
            "api": url_for("api.create_virtual_nao",name="v_red",port=9559)
        },
        {
            "id": "v_blue",
            "name": u"添加虚拟Nao: v_blue",
            "api": url_for("api.create_virtual_nao",name="v_blue",port=9560)
        }
    ]

    for nao_name in Nao.get_names():
        urls.append({"url": url_for('.nao_control',name=nao_name), "text": nao_name})
    return render_template('index.html',page_title=page_title,urls=urls,btns=btns)

@main.route('/virtual_nao/<string:name>/<int:port>', methods=['GET', 'POST'])
def virtual_nao(name,port):
    # 添加虚拟的 Nao , 使用 Webots 或 Ros gazebo 等

    return redirect(request.referrer)